package org.sensation.file.channel;

import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;

import org.sensation.file.channel.randomaccess.FileWriteChannelRandomAccess;

public class FileTransferChannel {
	private FileReadChannel readChannel;
	private FileWriteChannel writeChannel;

	public FileTransferChannel(String origin, String target) throws IOException {
		readChannel = new FileReadChannel(origin,(int) readChannel.size());
		writeChannel = new FileWriteChannelRandomAccess(target, (int) readChannel.size());
	}

	public void readFile(ByteBuffer buffer, int offset) throws IOException {
		readChannel.readFile(offset, buffer);
	}
	
	public void writeFile(ByteBuffer buffer) throws IOException {
		writeChannel.writeFile(buffer);
	}
	
	public void writeIndexAccessFile(int offset, ByteBuffer buffer) throws IOException{
		writeChannel.writeIndexAccessFile(offset, buffer);
	}

	@SuppressWarnings("unused")
	private void isFileExist(File file) throws IOException {
		if(file.exists())
			throw new IOException("target file exist.");
	}
	
	public long size(){
		return readChannel.size();
	}
	
	public void close() throws IOException {
		readChannel.close();
		writeChannel.close();
	}
}
